from flask import Flask,render_template
import pymysql

app = Flask(__name__)
@app.route('/')
def hello():
    sql = 'select * from cmswing_address limit 10'
    list = model(sql)
    return render_template('index.html',data=list)

@app.route('/add')
def add():
    return render_template('add.html')


def model(sql):
    db = pymysql.connect(host='localhost', user='root', password='123456', db='cmswing', charset='utf8mb4',
                         cursorclass=pymysql.cursors.DictCursor)

    try:
        cursor = db.cursor()

        row = cursor.execute(sql)

        data = cursor.fetchall()

        if data :
            return data
        else :
            return row

        print(data)
    except:
        db.rollback()

    finally:
        db.close()


if __name__ == '__main__' :
    app.run(debug=True,host='127.0.0.1',port='8080')